package com.ts.animal.controller;

import java.util.List;
import java.util.Map;

import com.ts.common.utils.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ts.animal.domain.HeartbeatRecordDO;
import com.ts.animal.service.HeartbeatRecordService;

/**
 * 基站心跳数据
 * 
 * @author bobby
 * @email bobby@126.com
 * @date 2023-04-07 14:30:49
 */
 
@Controller
@RequestMapping("/animal/heartbeatRecord")
public class HeartbeatRecordController {
	@Autowired
	private HeartbeatRecordService heartbeatRecordService;
	
	@GetMapping()
	@RequiresPermissions("animal:heartbeatRecord:heartbeatRecord")
	String HeartbeatRecord() {
		return "animal/heartbeatRecord/heartbeatRecord";
	}

	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("animal:heartbeatRecord:heartbeatRecord")
	public PageUtils list(@RequestParam Map<String, Object> params) {
		//查询列表数据
		PageUtils pageUtils = new PageInfos(params) {
			public List inject(Map params) {
				return heartbeatRecordService.list(params);
			}
		}.query();
		return pageUtils;
	}

	@GetMapping("/add")
	@RequiresPermissions("animal:heartbeatRecord:add")
	String add() {
		return "animal/heartbeatRecord/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("animal:heartbeatRecord:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		HeartbeatRecordDO heartbeatRecord = heartbeatRecordService.get(id);
		model.addAttribute("heartbeatRecord", heartbeatRecord);
	    return "animal/heartbeatRecord/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("animal:heartbeatRecord:add")
	public Result save( HeartbeatRecordDO heartbeatRecord){
		Result result = Result.ok();
		heartbeatRecordService.save(result,heartbeatRecord);
		return result;
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("animal:heartbeatRecord:edit")
	public Result update( HeartbeatRecordDO heartbeatRecord){
		Result result = Result.ok();
		heartbeatRecordService.update(result,heartbeatRecord);
		return result;
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("animal:heartbeatRecord:remove")
	public Result remove( Integer id){
		Result result = Result.ok();
		heartbeatRecordService.remove(result,id);
		return result;
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("animal:heartbeatRecord:batchRemove")
	public Result remove(@RequestParam("ids[]") Integer[] ids){
		Result result = Result.ok();
		heartbeatRecordService.batchRemove(result,ids);
		return result;
	}
	
}
